package com.numone.testble.ble;

import android.bluetooth.BluetoothDevice;

import java.util.List;

public class BleHelper {

    private BleScanPresenter bleScanPresenter;
    private BleConnectPresenter bleConnectPresenter;

    public BleHelper(){
        bleScanPresenter = new BleScanPresenter();
        bleConnectPresenter = new BleConnectPresenter();
    }

    /**
     * 获取已连接设备
     * @return
     */
    public BluetoothDevice getConnectedBle(){
        return bleConnectPresenter.getConnectedBle();
    }

    /**
     * 断开所有连接
     */
    public void disconnectAllDevice(){
        bleConnectPresenter.removeBondAllDevice();
    }

    public void scanBle(){
        bleScanPresenter.scanBle();
    }

    public boolean cancelScan(){
        return bleScanPresenter.cancelScan();
    }

    public void connectBle(String mac){
        bleConnectPresenter.connectBle(mac);
    }

    public void release(){
        if(null != bleConnectPresenter){
            bleConnectPresenter.unregisterConnectBroadcast();
        }
        if(null != bleScanPresenter){
            bleScanPresenter.unregisterScanBroadcast();
        }
    }

    public void setOnConnectCallBack(BleConnectPresenter.OnConnectCallBack onConnectCallBack) {
        bleConnectPresenter.setOnConnectCallBack(onConnectCallBack);
    }

    public void setOnBleScanCallback(BleScanPresenter.OnBleScanCallback onBleScanCallback) {
        if(null != bleScanPresenter){
            bleScanPresenter.setOnBleScanCallback(onBleScanCallback);
        }
    }

    public List<BleEntity> getBleList() {
        if(null != bleScanPresenter){
            return bleScanPresenter.getBleList();
        }
        return null;
    }
}
